using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CECompactTaskManager
{
    public static class Interop
    {
        public const int SWP_ASYNCWINDOWPOS = 0x4000;
        public const int SWP_DEFERERASE = 0x2000;
        public const int SWP_DRAWFRAME = 0x0020;
        public const int SWP_FRAMECHANGED = 0x0020;
        public const int SWP_HIDEWINDOW = 0x0080;
        public const int SWP_NOACTIVATE = 0x0010;
        public const int SWP_NOCOPYBITS = 0x0100;
        public const int SWP_NOMOVE = 0x0002;
        public const int SWP_NOOWNERZORDER = 0x0200;
        public const int SWP_NOREDRAW = 0x0008;
        public const int SWP_NOREPOSITION = 0x0200;
        public const int SWP_NOSENDCHANGING = 0x0400;
        public const int SWP_NOSIZE = 0x0001;
        public const int SWP_NOZORDER = 0x0004;
        public const int SWP_SHOWWINDOW = 0x0040;

        public const int HWND_TOP = 0;
        public const int HWND_BOTTOM = 1;
        public const int HWND_TOPMOST = -1;
        public const int HWND_NOTOPMOST = -2;

        public const uint WM_CLOSE = 0x0010;


        [DllImport("CoreDll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool TerminateProcess(IntPtr processIdOrHandle, uint exitCode);

        [DllImport("CoreDll.dll", SetLastError = true)]
        public static extern IntPtr OpenProcess(uint dwReqdASccess, bool bInheritHandle, uint dwProcessId);

        [DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
        public static extern IntPtr FindWindowCE(string lpClassName, string lpWindowName);

        [DllImport("coredll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
        
        [DllImport("coredll.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("coredll.dll", EntryPoint = "GetParent", SetLastError = true)]
        public static extern IntPtr GetWindowParent(IntPtr hWnd);


        public delegate int Callback(IntPtr hWnd, long lparam);

        [DllImport("coredll.dll", EntryPoint = "EnumWindows", SetLastError = true)]
        public static extern int EnumWindows(Callback lpEnumFunc, long lparam);

        [DllImport("coredll.dll", EntryPoint = "GetWindowText")] 
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);

        //public static string GetWindowTextRaw(IntPtr hwnd)
        [DllImport("coredll.dll", EntryPoint = "GetWindowTextRaw")]
        public static extern string GetWindowTextRaw(IntPtr hwnd);

                //public static string GetWindowTextRaw(IntPtr hwnd)
        [DllImport("coredll.dll", EntryPoint = "GetWindowTextLength")]
        public static  extern int GetWindowTextLength(IntPtr hWnd);

        [DllImport("coredll.dll", EntryPoint = "GetWindowThreadProcessId")]
        public static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr lpdwProcessId);

        [DllImport("coredll.dll", EntryPoint = "GetCurrentProcessId")]
        public static extern int GetCurrentProcessId();

        [DllImport("coredll.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);



        //MessageQForWinEnums_API
        [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "GetAppWindows", SetLastError = true)]
        public static extern void GetAppWindows ();

        [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "GetAppWindows2", SetLastError = true)]
        public static extern void GetAppWindows2();


       [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "GetWindowCount", SetLastError = true)]
       public static extern int GetWindowCount();

        [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "GetWindowDetails", SetLastError = true)]
       public static extern IntPtr GetWindowDetails(StringBuilder winText, int index);

        [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "Init", SetLastError = true)]
        public static extern void Init();

        [DllImport("\\Windows\\AppWindowsEnums.dll", EntryPoint = "DeInit", SetLastError = true)]
        public static extern void DeInit();
   
    }
}
